package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.AlbumItemBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class AlbumVideoAdapter extends StkProviderMultiAdapter<AlbumItemBean> {


    public AlbumVideoAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new AlbumVideoProvider());
    }

    private boolean isManage = false;

    public void setManage(boolean Manage) {
        isManage = Manage;
        notifyDataSetChanged();
    }

    private class AlbumVideoProvider extends BaseItemProvider<AlbumItemBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album_video;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, AlbumItemBean bean) {
            Glide.with(baseViewHolder.itemView).load(bean.getPath()).into((ImageView) baseViewHolder.getView(R.id.ivAlbumVideoItemImg));
            baseViewHolder.setText(R.id.tvAlbumVideoItemTime, TimeUtil.getMmss(MediaUtil.getDuration(bean.getPath())));
            if (isManage) {
                baseViewHolder.getView(R.id.ivAlbumVideoItemSel).setVisibility(View.VISIBLE);
                if (bean.isSelected()) {
                    baseViewHolder.setImageResource(R.id.ivAlbumVideoItemSel, R.drawable.icon_gx1);
                } else {
                    baseViewHolder.setImageResource(R.id.ivAlbumVideoItemSel, R.drawable.icon_gx1a);
                }
            } else {
                baseViewHolder.getView(R.id.ivAlbumVideoItemSel).setVisibility(View.GONE);
            }
        }
    }

}
